package com.ljxt.dt.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.ljxt.dt.util.RequestUtil;
import com.ljxt.dt.util.ServletUtil;
import com.ljxt.dt.vo.CkinVO;
import com.ljxt.dt.vo.JsonResult;
import javafx.scene.control.Skin;

import javax.json.Json;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 徐浩钦
 * @version 1.0.0
 * @date 2020/5/10 14:23
 * @copyright 老九学堂T11
 */
@WebServlet("/skin")
public class SkinServlet extends HttpServlet {
    public static CkinVO ckinVO = null;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        if(ckinVO == null) {
            ckinVO = new CkinVO();
            ckinVO.setBgSubject("ll-switch");
            ckinVO.setBgMenuColor("purple-bliss");
            ckinVO.setBgImgUrl("img-03");
            ckinVO.setBgImgSwitch(false);
            ckinVO.setBgSimplifyMenu(true);
            ckinVO.setBgMenuWidth("small");
            ckinVO.setBgSubjectRenderer("img-04");
            ckinVO.setBgSubjectColor("bg-tundora");
        }


        // 将菜单对象转换为 json 字符串
        ObjectMapper objectMapper = new ObjectMapper();
        String strSkinVO = objectMapper.writeValueAsString(ckinVO);

        resp.getWriter().write(strSkinVO);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ckinVO = RequestUtil.reqToObj(req,CkinVO.class);

        JsonResult jsonResult = new JsonResult();
        ObjectMapper objectMapper = new ObjectMapper();
        resp.getWriter().write(objectMapper.writeValueAsString(jsonResult));
    }
}
